SET(TEST_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR})

MACRO(ADD_SU_TEST TEST_NAME)

    # message("TEST_ROOT_DIR: ${TEST_ROOT_DIR}")
    # message("CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
    SET(TRG_NAME "${TEST_NAME}")

    STRING(REPLACE "${TEST_ROOT_DIR}" "" TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
    if (TEST_PATH)
        STRING(SUBSTRING "${TEST_PATH}" 1 -1 TEST_PATH)         # Remove initial /
        STRING(REPLACE "/" "__" TEST_PREFIX "${TEST_PATH}/")    # Replace / by __
        # message("TEST_PREFIX: ${TEST_PREFIX}")
        STRING(PREPEND TRG_NAME "${TEST_PREFIX}")
    endif()
    SET(TRG_NAME "SimoxUtility__${TRG_NAME}")
    # message("TRG_NAME: ${TRG_NAME}")

    ADD_EXECUTABLE(${TRG_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/${TEST_NAME}.cpp)
    TARGET_LINK_LIBRARIES(${TRG_NAME} PRIVATE SimoxUtility Boost::unit_test_framework)
    target_include_directories(${TRG_NAME} PRIVATE ${PROJECT_SOURCE_DIR}/..)
    if (NOT Boost_USE_STATIC_LIBS)
        target_compile_definitions(${TRG_NAME} PRIVATE -DBOOST_TEST_DYN_LINK)
    endif ()
    SET_TARGET_PROPERTIES(${TRG_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${Simox_TEST_DIR})
    SET_TARGET_PROPERTIES(${TRG_NAME} PROPERTIES FOLDER "SimoxUtility Tests")
    ADD_TEST(NAME ${TRG_NAME}
        COMMAND ${Simox_TEST_DIR}/${TRG_NAME} --output_format=XML --log_level=all --report_level=no)
ENDMACRO()


ADD_SUBDIRECTORY(algorithm)
ADD_SUBDIRECTORY(color)
ADD_SUBDIRECTORY(filesystem)
ADD_SUBDIRECTORY(json)
ADD_SUBDIRECTORY(math)
ADD_SUBDIRECTORY(meta)
ADD_SUBDIRECTORY(shapes)
ADD_SUBDIRECTORY(simox)
ADD_SUBDIRECTORY(backport)
